﻿using DataEntity;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Tools;
using DataAccess;

namespace WebUI.Controllers
{
    public class ZZZController : Controller
    {
        //
        // GET: /ZZZ/
        private DataAccess.DataContext dc = new DataAccess.DataContext();

        private IEntityRepository<SysUser> UserRepository;
        public ZZZController()
        {
            UserRepository = new EntityRepository<SysUser>(dc);
        }
        public ActionResult Index()
        {
            
            return View();
        }
        /// <summary>
        /// 密码解析
        /// </summary>
        /// <param name="pwd">加密或解密的字符串</param>
        /// <param name="type">加密还是解密，de解密，en加密，默认解密</param>
        /// <returns></returns>
      
        public ActionResult EnOrDe(string pwd, string type = "de")
        {
            Encrypt en = new Encrypt(); string result = "";
            if (type == "de")
            {
                result = en.Decode(pwd);
            }
            else
            {
                result = en.Encode(pwd);
            }

            return Json(new { success = true, result = result });
        }

        public ActionResult Index1()
        {
            string msg = string.Empty;

            List<SysUser> list = new List<SysUser>();

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            SysUser model = new SysUser();

            model.UserName = "admin";
            model.Password = "1";
            model.Mobile="2312312";
            model.RealName = "张三";
            model.Sex = true;
            model.SysRoleID = 6;
            model.Tel = "1111";
            UserRepository.Insert(model);
          

            stopwatch.Stop();

            msg += "首次1条数据：" + stopwatch.ElapsedMilliseconds + "毫秒</br>";

            for (int i = 0; i < 10000; i++)
            {
                list.Add(new SysUser
                {
                    UserName = "action"+i,
           Password = "1",
            Mobile="2312312",
         RealName = "张三",
        Sex = true,
        SysRoleID = 6,
         Tel = "1111"
                });
            }

            stopwatch.Restart();

            UserRepository.Insert(list);

            stopwatch.Stop();

            msg += "二次10000条数据（自动ID）：" + stopwatch.ElapsedMilliseconds + "毫秒</br>";

            

            msg += "注：手动ID也会在封装中判断ID是否存在，并且添加个更新时间都是自动赋值!";

            ViewBag.Msg = msg;
            return View();
        }

    }
}
